package com.asus.api;

import java.util.ArrayList;
import java.util.HashMap;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class LoginApi extends ApiBase
{

	public LoginApi(HashMap<String, String> pHashMap)
	{
		super("https://vip.asus.com/webservice/app_cusinfo.asmx/QryRegProfile?",pHashMap);
	}

	private HashMap<String, String> mAccountHashMap = new HashMap<String, String>();
	
	public HashMap<String, String> getAccountHashMap()
	{
		return mAccountHashMap;
	}

	private ArrayList<HashMap<String, String>> mProduct = new ArrayList<HashMap<String, String>>();

	public Boolean Start()
	{
		if (Run())
		{
			try
			{
				NodeList _List = mRootElement
						.getElementsByTagName("CustomerInfo");
				NodeList _List2 = _List.item(0).getChildNodes();

				for (int j = 0; j < _List2.getLength(); j++)
				{
					if (_List2.item(j).getNodeName() == "#text")
					{
					} else
					{
						
						mAccountHashMap.put(_List2.item(j).getNodeName(),
								_List2.item(j).getTextContent());
						
						
						if(_List2.item(j).getNodeName().equals("Ticket"))
						{
							mTicket = _List2.item(j).getTextContent();
						}
						
						if(_List2.item(j).getNodeName().equals("Cus_id"))
							
						{
							mCusId = _List2.item(j).getTextContent();
						}
					}

				}

				NodeList _List3 = mRootElement.getElementsByTagName("Product");

				for (int i = 0; i < _List3.getLength(); i++)
				{
					HashMap<String, String> _HashMap = new HashMap<String, String>();
					for (int j = 0; j < _List3.item(i).getChildNodes()
							.getLength(); j++)
					{
						Node _Node = _List3.item(i).getChildNodes().item(j);
						if (_List3.item(i).getChildNodes().item(j)
								.getNodeName() == "#text")
						{
						} else
						{
							_HashMap.put(_Node.getNodeName(),
									_Node.getTextContent());
						}
					}
					mProduct.add(_HashMap);
				}

				return true;

			} catch (Exception e)
			{
				e.printStackTrace();
				return false;
			}
		}
		return false;
	}
}
